import ccp as ccp

from celery_tasks.main import app
from meiduo_mall.utils.yuntongxun.sms import CCP


@app.task(bind=True, name='send_sms_code')
def send_msg(self, phone, sms_code, time):
    # 发送短信
    try:
        ccp = CCP()
        # import time
        # time.sleep(10)
        res = ccp.send_template_sms(phone, [sms_code, time], 1)
        print(sms_code)
    except Exception as e:
        res = -1

    # 2判断短信是否发送成功

    if res == -1:
        print('短信发送失败')
        '''
        ext : 没发送成功的报错信息
        count_down : 重发时间间隔
        max_retries : 重新发送的最大次数
        '''
        self.retry(exc=Exception('没有发送成功'), countdown=5, max_retries=3)
